local xiongzhi = fk.CreateSkill{
    name = "jinhs__xiongzhi",
    tags = { Skill.Limited },
}

Fk:loadTranslationTable{
    ["jinhs__xiongzhi"] = "雄志",
    [":jinhs__xiongzhi"] = "限定技，出牌阶段，你可以观看牌堆顶的X张牌(X为你的体力上限)，然后你可以使用其中一张牌(无距离次数限制)；"..
    "结束阶段，若本回合内有角色死亡，此技能视为未发动过。",

    ["#jinhs__xiongzhi"] = "雄志：你可以观看牌堆顶你的体力上限张牌，然后你可以使用其中一张牌（无距离次数限制）",
    ["#jinhs__xiongzhi-use"] = "雄志：你可以使用其中一张牌",
    ["#jinhs__xiongzhi_active"] = "雄志",

    ["$jinhs__xiongzhi1"] = "烈士雄心，志存高远。",
    ["$jinhs__xiongzhi2"] = "乱世之中，唯我司马！",
}

xiongzhi:addEffect("active",{
    anim_type = "special",
    prompt = "#jinhs__xiongzhi",
    card_num = 0,
    can_use = function (self, player)
        return player:usedSkillTimes(xiongzhi.name, Player.HistoryGame) == 0 and player.phase ~= Player.NotActive
    end,
    target_num = 0,
    on_use = function (self, room, effect)
        local player = effect.from
        local result, dat = room:askToUseActiveSkill(player, {
            skill_name = "#jinhs__xiongzhi_active",
            prompt = "#jinhs__xiongzhi-use",
            cancelable = true,
        })
        if result and dat then
            room:useCard({
                card = Fk:getCardById(dat.cards[1]),
                from = player,
                tos = dat.targets,
                extraUse = true,
            })
        end
    end,
})

xiongzhi:addEffect(fk.EventPhaseStart,{
    late_refresh = true,
    can_refresh = function (self, event, target, player, data)
        return target == player and player:hasSkill(xiongzhi.name) and player.phase == Player.Finish and player:usedSkillTimes(xiongzhi.name, Player.HistoryTurn) > 0
        and #player.room.logic:getEventsOfScope(GameEvent.Death, 1, Util.TrueFunc, Player.HistoryTurn) > 0
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        target:addSkillUseHistory(xiongzhi.name, -1)
        player:broadcastSkillInvoke(xiongzhi.name)
        room:notifySkillInvoked(player, xiongzhi.name, "special")
        player.room:sendLog{
          type = "#XiongsuanReset",
          from = target.id,
          arg = xiongzhi.name,
          toast = true,
        }
    end,
})

xiongzhi:addEffect("targetmod", {
  bypass_distances =  function(self, player, skill, card, to)
    return card and table.contains(card.skillNames, xiongzhi.name)
  end,
  bypass_times = function (self, player, skill, scope, card, to)
    return card and table.contains(card.skillNames, xiongzhi.name)
  end
})

return xiongzhi